#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QPushButton>
#include <QInputDialog>
#include <QDebug>
#include <QVBoxLayout>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    QPushButton* b_double = new QPushButton("浮点型输入框");
    connect(b_double, &QPushButton::clicked, [=](){
       double d = QInputDialog::getDouble(this, "输入框", "浮点型");
       qDebug() << "浮点型d = " << d;
    });

    QPushButton* b_int = new QPushButton("整型输入框");
    connect(b_int, &QPushButton::clicked, [=](){
       int i = QInputDialog::getInt(this, "输入框", "整数型");
       qDebug() << "整数型i = " << i;
    });

    QPushButton* b_item = new QPushButton("条目型输入框");
    connect(b_item, &QPushButton::clicked, [=](){
       QStringList items;
       // 两种输入方式
       items << tr("Spring") << tr("Summer") << tr("Fall");
       items.push_back("Winter");

       QString it = QInputDialog::getItem(this, "输入框", "条目型", items);
       qDebug() << "条目型it = " << it;
    });

    QVBoxLayout* lay = new QVBoxLayout();

    lay->addWidget(b_double);
    lay->addWidget(b_int);
    lay->addWidget(b_item);

    // 创建一个 QWidget 作为中心部件
    QWidget* centralWidget = new QWidget(this);
    centralWidget->setLayout(lay);  // 将布局设置到中心部件上

    // 将中心部件设置到 QMainWindow 上
    this->setCentralWidget(centralWidget);
}

MainWindow::~MainWindow()
{
    delete ui;
}

